﻿<%@ Page Language="C#" AutoEventWireup="false" CodeFile="sMenuform.aspx.cs" Inherits="Training.Web.Forms.Administration.UserManagement.sMenuform" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Menu Form</title>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.wrapper.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.msgBox.v1.js") %>" type="text/javascript"></script>
    <script type="text/javascript">

        $("#btnSave").button({ icons: { primary: "ui-icon-disk"} });
        $("#btnClose").button({ icons: { primary: "ui-icon-close"} });
 
    </script>
    <script type="text/javascript">

        $(document).ready(function () {

            $('#txtName').focus();
            // 1. prepare the validation rules and messages.
            var rules = {
                txtName: {
                    required: true,
                    maxlength: 50
                },
                txtOrderSeq: "required"
            };
            var messages = {
                txtName: {
                    required: "Nama menu wajib di isi",
                    maxlength: "Panjang nama menu maksimalnya adalah 50"
                },
                txtOrderSeq: "Order seq wajib di isi"
            };

            // 2. Initiate the validator
            var validator = new jQueryValidatorWrapper("form1", rules, messages);

            // 3. Set the click event to do the validation
            $("#btnSave").click(function () {

                if (!validator.validate())
                    return;

                var name = $('#txtName').val();
                var menuUrl = $('#txtUrl').val();
                var orderSeq = $('#txtOrderSeq').val();
                var parentValue = $("#ddlParent option:selected").val();

                var id = $('#<%= hfID.ClientID %>').val();

                var objMenu = new Object();
                objMenu.MenuID = id;
                objMenu.MenuName = encodeURIComponent(name);
                objMenu.URL = encodeURIComponent(menuUrl);
                objMenu.OrderSeq = encodeURIComponent(orderSeq);
                objMenu.ParentID = encodeURIComponent(parentValue);

                jsonData = JSON.stringify(objMenu);

                if (id == 0)
                    CallAjax('<%= ResolveUrl("~/ajaxhandler/administration/usermanagement/sMenuhandler.ashx") %>', "?method=insert", jsonData);
                else
                    CallAjax('<%= ResolveUrl("~/ajaxhandler/administration/usermanagement/sMenuhandler.ashx") %>', "?method=update", jsonData);

                parent.$('#dialog').dialog('close');

                setTimeout(" window.parent.location.reload();", 3000);

                return false;
            });

        });
    
    </script>
    <script type="text/javascript">

        function ClearText() {
            $('#txtName').val('');
            $('#txtUrl').val('');
            $('#txtOrderSeq').val('');

        }

        $('#btnClose').click(function () {

            parent.$('#dialog').dialog('close');

            return false;
        });        
         
    </script>
</head>
<body onload="ClearText();">
    <form id="form1" runat="server">
    <table border="0">
        <tr>
            <td style="width: 50">
                Name
            </td>
            <td>
                :
            </td>
            <td>
                <asp:TextBox ID="txtName" runat="server" Width="300" MaxLength="50"></asp:TextBox>&nbsp;<span
                    style="color: Red;">*</span>
            </td>
        </tr>
        <tr>
            <td style="width: 50">
                URL
            </td>
            <td>
                :
            </td>
            <td>
                <asp:TextBox ID="txtUrl" runat="server" Width="300"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td style="width: 50">
                Parent
            </td>
            <td>
                :
            </td>
            <td>
                <asp:DropDownList ID="ddlParent" runat="server">
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td style="width: 50">
                Order Seq
            </td>
            <td>
                :
            </td>
            <td>
                <asp:TextBox ID="txtOrderSeq" runat="server" MaxLength="3" Width="60"></asp:TextBox>&nbsp;<span
                    style="color: Red;">*</span>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                &nbsp;
            </td>
            <td>
                <div style="text-align: right; padding-top: 10px;">
                    <button id="btnSave" type="button">
                        Save</button>
                    <button id="btnClose" type="button">
                        Close</button>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                &nbsp;
            </td>
            <td>
                <asp:HiddenField ID="hfID" runat="server" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
